package com.ttc.mBackup.BackupContacts;

import java.util.*;




import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class CustomListAdapter extends BaseAdapter {

	ArrayList<Contact> listContacts;
	int resource;
	Context context;
	
	

	public CustomListAdapter(Context context, int textViewResourceId,
			ArrayList<Contact> objects) {


		this.context = context;
		resource = textViewResourceId;
		listContacts = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = new CustomList(context);
		}

		final Contact item = listContacts.get(position);

		if (convertView != null) {
			TextView contactNameTextView = ((CustomList) convertView).getTxtContactName();
			TextView numberPhoneTextView=((CustomList)convertView).getTxtNumberPhone();
					
			CheckBox checkbox = ((CustomList) convertView).getCheckbox();
			checkbox.setChecked(item.isChecked());
			checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                	
                    item.setChecked(isChecked);                    
                }                
            });

			
			contactNameTextView.setText(item.getStructuredName().getDisplayName());
			numberPhoneTextView.setText(item.getPhones().get(0).getNumber());
			
			
			//icon.setImageResource(R.drawable.icon);

		}
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listContacts.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listContacts.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
